//
//  ConfigMoudle.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2017/8/31.
//  Copyright © 2017年 niuwaketang. All rights reserved.
//

#import "ConfigMoudle.h"
#import "RequestUrlFilter.h"
#import "RMUUid.h"
#import "MainServiceProtocol.h"
#import <EAIntroView/EAIntroView.h>
#import "PayManager.h"

@implementation ConfigMoudle
- (void)basicModuleLevel
{
}
- (void)modSetUp:(BHContext *)context
{
        [self _ShowIntroView];
        
        [self _SetupNetwork:context];
        
        [self _SetupUITheme];
        
        [self _SetupIQKeyboardManager:(context.env == BHEnvironmentDev)];
        
        [self _ConfigQMUIAlert];
        
        [[HLNetWorkReachability shareManager] startNotifier];
        
#if WGEnablePgyerSDK
        [[PgyManager sharedPgyManager] startManagerWithAppId:PGYER_APP_KEY];
#endif
        [[PayManager manager] application:context.application didFinishLaunchingWithOptions:context.launchOptions];
}

- (void)_ShowIntroView
{
        if ([AppUnit isFirstLaunching])
        {
                
                NSArray <UIImage *>*imgs = @[[UIImage intro_1],[UIImage intro_2],[UIImage intro_3],];
                NSMutableArray <EAIntroPage *>*pages = [NSMutableArray arrayWithCapacity:imgs.count];
                [imgs enumerateObjectsUsingBlock:^(UIImage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                        EAIntroPage *page = [EAIntroPage page];
                        page.bgImage = obj;
                        [pages addObject:page];
                }];
                EAIntroView *intro = [[EAIntroView alloc] initWithFrame:[UIScreen mainScreen].bounds andPages:pages];
                [intro showFullscreenWithAnimateDuration:0];
        }
}

- (void)_SetupNetwork:(BHContext *)context
{
        YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
        [config addUrlFilter:[RequestUrlFilter filter]];
        
        switch (context.env)
        {
                case BHEnvironmentDev:
                {
                        config.debugLogEnabled = NO;
                        config.baseUrl = kRequestUrlBaseTest; // 可以任意修改此选项, 来适配不同的 Debug 下的服务器端
                }
                        break;
                case BHEnvironmentTest:
                {
                        config.debugLogEnabled = NO;
                        config.baseUrl = kRequestUrlBaseTest;
                }
                        break;
                case BHEnvironmentStage:
                {
                        config.debugLogEnabled = NO;
                        config.baseUrl = kRequestUrlBaseOnline;
                }
                        break;
                case BHEnvironmentProd:
                {
                        config.debugLogEnabled = NO;
                        config.baseUrl = kRequestUrlBaseOnline;
                }
                        break;
                        
                default:
                {
                        config.debugLogEnabled = NO;
                        config.baseUrl = kRequestUrlBaseOnline;
                }
                        break;
        }
}


- (void)_SetupUITheme
{
        QMUIConfigurationTemplate *template = [[QMUIConfigurationTemplate alloc] init];
        [template setupConfigurationTemplate];
        [[QDThemeManager sharedInstance] setCurrentTheme:template];
}

- ( void )_SetupIQKeyboardManager:(BOOL)debug
{
        // 设置智能键盘处理
        IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
        manager.enable = YES;
        manager.shouldResignOnTouchOutside = YES;
        manager.shouldToolbarUsesTextFieldTintColor = NO;
        manager.enableAutoToolbar = NO;
        manager.enableDebugging = debug;
        [manager registerTextFieldViewClass:[YYTextView class] didBeginEditingNotificationName:YYTextViewTextDidBeginEditingNotification didEndEditingNotificationName:YYTextViewTextDidEndEditingNotification];
        [manager registerTextFieldViewClass:[QMUITextField class] didBeginEditingNotificationName:UITextFieldTextDidBeginEditingNotification didEndEditingNotificationName:UITextFieldTextDidEndEditingNotification];
        [manager registerTextFieldViewClass:[US2ValidatorTextField class] didBeginEditingNotificationName:UITextFieldTextDidBeginEditingNotification didEndEditingNotificationName:UITextFieldTextDidEndEditingNotification];
        [manager registerTextFieldViewClass:[US2ValidatorTextView class] didBeginEditingNotificationName:UITextViewTextDidBeginEditingNotification didEndEditingNotificationName:UITextViewTextDidEndEditingNotification];
}
- (void)_ConfigQMUIAlert
{
        QMUIAlertController *alert = [QMUIAlertController appearance];
        
        alert.sheetButtonHeight = __WGHeight(50.0f);
        alert.sheetContentCornerRadius = 0;
        alert.sheetButtonBackgroundColor = [UIColor whiteColor];
        alert.sheetHeaderInsets = UIEdgeInsetsZero;
        alert.sheetHeaderInsets = UIEdgeInsetsZero;
        alert.sheetContentMargin = UIEdgeInsetsZero;
        alert.sheetSeperatorColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
        alert.sheetBackgroundColor = [UIColorHex(0x939393) colorWithAlphaComponent:1];
        alert.sheetTitleMessageSpacing = 0;
        alert.sheetCancelButtonMarginTop = __WGHeight(6);
        alert.sheetContentMaximumWidth = __MAIN_SCREEN_WIDTH__;
        NSDictionary *titleAttribute = @{
                                         NSFontAttributeName : WGSystem16Font,
                                         NSForegroundColorAttributeName : UIColorHex(0x323232)
                                         };
        alert.sheetTitleAttributes = titleAttribute;
        alert.sheetButtonAttributes = titleAttribute;
        alert.sheetButtonDisabledAttributes = titleAttribute;
        alert.sheetCancelButtonAttributes = titleAttribute;
}

@end
